/*	____________________________________________________________________________

	                 Scanner Component for the PhiMP Compiler
	____________________________________________________________________________  */


#ifndef SCANNER
#define SCANNER
#include <string>

const int ID_STRING_LEN = 256;

enum Token { CHAR_TYPE = 1, INT_TYPE, REAL_TYPE,																			//  ||
			PROGRAM_SYM, VAR_SYM, READ_SYM, READLN_SYM, WRITE_SYM, WRITELN_SYM,	EOF_SYM, 									//  ||
			LPAREN, RPAREN, SEMICOLON, COMMA, LBRACKET, RBRACKET, LCURL, RCURL,												// \  /
			ASSIGN_OP, PLUS_OP, MINUS_OP, MULT_OP, DIV_OP, POW_OP, INT_DIV_OP, MOD_OP,										//  \/
			ID, INT_LITERAL, REAL_LITERAL, CHAR_LITERAL, STR_LITERAL, TRUE, FALSE,											// C Level
			BOOL_TYPE, BOOL_LITERAL, IF_SYM, ELIF_SYM, ELSE_SYM, AND_OP, OR_OP, LT_OP, LTE_OP, NE_OP, GT_OP, GTE_OP, EQ_OP,	// B Level
			FOR_SYM, WHILE_SYM, FUNCT_SYM, RETURN_SYM, COLON  };																		// A level 

class Scanner
{
public:

	string	tokenBuffer, // current token
			lineBuffer;  // current line
	int		lineNumber;  // line counter

	Scanner();
	// Initializes the scanner object.

	Token GetNextToken();
	// Retrieves the next token available in the input stream.

private:

   void BufferChar(char c);
   // Appends character c to the end of the token buffer provided that the
   // buffer is not full.

   void BufferString(string sz);
   // Appends the string to the buffer, assuming it is not full

   Token CheckReserved();
   // Checks the identifier in the token buffer to see if it is a reserved word
   // or a user-defined identifier and returns the appropriate token.

   void ClearBuffer();
   // Erases the contents of the tokenBuffer.

   void LexicalError(char& c);
   // Processes a lexical error at character c by ignoring that character and 
   // getting the next character.

   char NextChar();
   // Gets next available character from the source file.
};
#endif